/*
 * PrecioHoraPane.java
 *
 * Created on 27 de junio de 2006, 05:42 PM
 */

package inc.jmc.cyberboard.ztrashcan;
import javax.swing.*;
import java.awt.*;

/**
 *
 * @author  Juan Miguel Olguin Salguero
 */
public class PrecioHoraPane extends javax.swing.JPanel {
    
    private javax.swing.table.DefaultTableModel dtm=null;
    java.text.NumberFormat nf= java.text.NumberFormat.getInstance();
    java.text.NumberFormat nf2= java.text.NumberFormat.getInstance();
    
    /** Creates new form PrecioHoraPane */
    public PrecioHoraPane() {
        initComponents();
        initTable();
    }
    
    void initTable()
    {
        String []  titulos=new String [3];
        Object [][] content=new Object [24][3];
        ////
        //estableciendo los titulos para la tabla
        
        titulos[0]="Minuto inicial";
        titulos[1]="Minuto final";
        titulos[2]="Precio";
        
        
        dtm=new javax.swing.table.DefaultTableModel(content,titulos);
        jTable1.setModel(dtm);
        if(jTable1.getTableHeader()!=null)
          jTable1.getTableHeader().setReorderingAllowed(false);
        //jTable1.setColumnSelectionAllowed(false);
        //jTable1.setCellSelectionEnabled(false);
        jTable1.getColumnModel().setColumnMargin(0);
        
        jTable1.getColumnModel().getColumn(0).setResizable(false);
        jTable1.getColumnModel().getColumn(1).setResizable(false);
        jTable1.getColumnModel().getColumn(2).setResizable(false);
        
        jScrollPane1.setViewportView(jTable1);
        jScrollPane1.updateUI();
        
    
    
    
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        aplicatBtn = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setLayout(null);

        jPanel1.setLayout(null);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Precios", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14)));
        aplicatBtn.setText("Aplicar");
        jPanel1.add(aplicatBtn);
        aplicatBtn.setBounds(30, 220, 73, 23);

        jTable1.setBackground(new java.awt.Color(229, 255, 255));
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable1.setGridColor(new java.awt.Color(255, 51, 0));
        jTable1.setSelectionBackground(new java.awt.Color(130, 204, 255));
        jScrollPane1.setViewportView(jTable1);

        jPanel1.add(jScrollPane1);
        jScrollPane1.setBounds(10, 30, 310, 180);

        add(jPanel1);
        jPanel1.setBounds(10, 10, 330, 260);

    }// </editor-fold>//GEN-END:initComponents
    
    void setTarifaIntervalos(int divisiones,Float precioIncremento)
    {
        String []  titulos=new String [divisiones+10];
        Object [][] content=new Object [1][divisiones];
        ////
        //estableciendo los titulos para la tabla
        float increm=(float)60/divisiones;
        
        for(int i=0;i<divisiones;++i)
        {
            
            float inf=increm*i;
            if(inf==1)
                inf=0;
            float sup=increm*(i+1);
            titulos[i]="["+nf2.format(inf)+" - "+nf2.format(sup)+" ]mins";
            if(precioIncremento!=null)
            {
                    content[0][i]=nf.format(precioIncremento.floatValue()*(i+1));
                
            }
            else
            {
                content[0][i]="";
            }
        
        }
        
        dtm=new javax.swing.table.DefaultTableModel(content,titulos);
        jTable1.setModel(dtm);
        jTable1.setPreferredSize(new java.awt.Dimension(80*titulos.length,60));
        jTable1.setMaximumSize(new java.awt.Dimension(80*titulos.length,60));
        jTable1.setMinimumSize(new java.awt.Dimension(80*titulos.length,60));
        if(jTable1.getTableHeader()!=null)
          jTable1.getTableHeader().setReorderingAllowed(false);
        jTable1.setColumnSelectionAllowed(false);
        jTable1.setCellSelectionEnabled(false);
        int max=jTable1.getColumnModel().getColumnCount();
        jTable1.getColumnModel().setColumnMargin(0);
        
        for(int i=0;i<max;++i)
        {
            jTable1.getColumnModel().getColumn(i).setResizable(false);
        }
        JTextField aux1=new javax.swing.JTextField();
        aux1.setEditable(false);
        javax.swing.DefaultCellEditor aux2=new javax.swing.DefaultCellEditor(aux1);
        for(int i=0;i<10;++i)
        {
            jTable1.getColumnModel().getColumn(divisiones+i).setCellEditor(aux2);
        }
        jScrollPane1.setViewportView(jTable1);
        jScrollPane1.updateUI();
        
    
    
    
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton aplicatBtn;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
    
}
